package com.fr.lintcode;

import java.util.Stack;

public class Q1759 {

    /**
     * @param root: the root of the binary tree
     * @return: the number of nodes
     */
    public int getAns(TreeNode root) {
        // Write your code here
    	int count = 0;
    	if(root == null) {
    		return count;
    	}
    	Stack<TreeNode> stack = new Stack<>();
    	stack.add(root);
    	while(!stack.isEmpty()) {
    		count ++;
    		TreeNode node = stack.pop();
    		if(node.left != null) {
    			stack.add(node.left);
    		}
    		if(node.right != null) {
    			stack.add(node.right);
    		}
    		
    	}
    	return count;
    }


}
